/**
 * @author BoLiang
 */
if (typeof accedo === "undefined") {
	accedo = {};
}
if (typeof accedo.achievement === "undefined") {
	accedo.achievement = {};
}

accedo.achievement.popup = {
		divPopupNode : null,
		divCtnNode : null,
		
		init : function() {
			divPopupNode = null;
			divCtnNode = null; 
		},
		
		createPopupDiv : function() {
			
			
			
			this.divPopupNode = document.createElement("div"); 
			this.divPopupNode.id = "divPopup"; 
			
			this.divCtnNode = document.createElement("div"); 
			this.divCtnNode.id = "divPopupCtn";
			
			this.divCtnNode.appendChild(this.divPopupNode); 
			
			var bodyNode = document.getElementsByTagName("body")[0]; 
			bodyNode.appendChild(this.divCtnNode); 		
		},
		
		initPopup : function(username, achi_sn) {
			dwr.engine.setPreHook(this.preHook); 
			dwr.engine.setPostHook(this.postHook); 
			AchiService._path = "http://"
								+ accedo.achievement.config.serverIP + ":" 
								+ accedo.achievement.config.serverPort + "/" 
								+ accedo.achievement.config.pluginName + "/dwr";
			AchiService.unlockAndJsonPopup(username, achi_sn, this.initPopupCallback);
		},
		preHook : function() {
			
		},
		postHook : function() {
			
		},
		initPopupCallback : function(data) {
			var serverDataObj = eval("(" + data + ")");
			
			var divStarNode = document.createElement("div");
			divStarNode.id = "divPopupStar";
			divStarNode.innerHTML = "<img src='http://"
								+ accedo.achievement.config.serverIP + ":" 
								+ accedo.achievement.config.serverPort + "/" 
								+ accedo.achievement.config.pluginName + "/achiPlugin/achi-images/achiStar.png' />";
			
			var divContNode = document.createElement("div");
			divContNode.id = "divPopupCont";
			divContNode.innerHTML = "<font color='white'>YOU UNLOCKED ACHIEVEMENT: "
					+ serverDataObj.achi_name 
					+ " & YOU GOT THE CARD: "
					+ serverDataObj.card_sn
					+ "</font>";
			accedo.achievement.popup.divPopupNode.appendChild(divStarNode);
			accedo.achievement.popup.divPopupNode.appendChild(divContNode);			
		},
		
		appendPopup : function(username, achi_sn) {
			this.init(); 
			this.createPopupDiv(); 
			this.initPopup(username, achi_sn);
			this.divPopupNode.className = "start"; 
		}
};